package fulbitofacil.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import fulbitofacil.exception.DAOExcepcion;
import fulbitofacil.negocio.EventoNegocio;
import fulbitofacil.negocio.UsuarioNegocio;

/**
 * Servlet implementation class EventoServlet
 */
@WebServlet("/EventoServlet")
public class EventoServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public EventoServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		String nombre = request.getParameter("nombre");
		String premio = request.getParameter("premio");
		String numEquipos = request.getParameter("numEquipos");
		String plazo = request.getParameter("hasta");
	
		HttpSession sesion = request.getSession();
		//String usuario = (String)sesion.getAttribute("usuario");
		
		EventoNegocio neg = new EventoNegocio();

		try{ 
			neg.insertarEvento(nombre, premio, numEquipos, plazo, 1);
			
		}catch(DAOExcepcion e){
			e.printStackTrace();
		}
		
		String cadena = "Registrado";
	    request.setAttribute("exito", cadena);
	    	    
	    //PrintWriter out = response.getWriter();
		//out.println("<html><body>"+cadena+"</body></html>");
		
	    RequestDispatcher rd = request.getRequestDispatcher("Evento.jsp"); //con esto se separa HTML y JAVA
	    rd.forward(request, response);

	    

		
	}

}
